<?php


namespace App\Http\observer;


use App\Models\Image;
use App\Models\TurntableActive;
use Illuminate\Support\Facades\Cache;

class TurntableActiveObserver
{
    public function updating(TurntableActive $active)
    {
        $old_active=TurntableActive::where("id",$active["id"])->first();
        if($old_active["icon"]){
            Cache::put("turntable_actives_icon",$old_active["icon"]);
        }
    }

    public function updated(TurntableActive $active)
    {
        $icon=Cache::get("turntable_actives_icon");
        Cache::forget("turntable_actives_icon");
        if ($icon&&$icon!=$active->icon){
            Image::del_data($icon);
        }

    }

    public function deleted(TurntableActive $active)
    {
        if($active->icon){
            Image::del_data($active->icon);
        }
    }
}
